import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class rcsCP extends JFrame implements ActionListener
{

    private JButton ban, kick, mute;
    private JPanel panel;
    private JLabel value, players, online;
    private JTextField player;
    public client c;
    public boolean Enabled = false;

    public rcsCP()
    {
if (Enabled) {
	playerChecker();
        //The components added to the control panel
        panel = new JPanel();
        ban = new JButton("Ban");
        kick = new JButton("Kick");
        mute = new JButton("Mute");
        value = new JLabel("Player:");
        player = new JTextField(10);
	players = new JLabel("Players online:");
	online = new JLabel(""+PlayerHandler.getPlayerCount());

        //Changes the font to Times New Roman
        Font f = new Font("Times New Roman", Font.PLAIN, 14);

        //Adds the Action Listener to the buttons
        ban.addActionListener(this);
        kick.addActionListener(this);
        mute.addActionListener(this);

        //Adds the components to the panel
        panel.add(value);
        panel.add(player);
	panel.add(players);
        panel.add(ban);
        panel.add(kick);
        panel.add(mute);
	panel.add(online);

       //Sets the font of the components
        value.setFont(null);
        player.setFont(null);
	players.setFont(null);
        ban.setFont(null);
        kick.setFont(null);
        mute.setFont(null);
	online.setFont(null);

        //Sets the color of the components
        panel.setBackground(Color.BLUE);
        panel.setForeground(Color.RED);


       //Sets the title, size, font, and visibility of the frame. Then adds the panel to the frame.
       this.setTitle("Runecrafterscape CP - v1.0");
       this.setFont(f);
       this.setSize(300, 300);
       this.setVisible(true);
       this.setResizable(false);
       this.add(panel);
	}
	if (!Enabled) {
		sM("Control panel disabled!");
	}

    }

    //Listens for an event to occur

    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource() == ban)
        {
            /*PlayerHandler.kickNick = player.getText();
            c.appendToBanned(player.getText());*/
        }
        
        if(e.getSource() == mute)
        {
         
         }

        if(e.getSource() == kick)
        {
           PlayerHandler.kickNick = player.getText();
	   sM("[CP] Player: "+player.getText()+" was kicked from in-game.");
        }

    }

public void sM(String msg) {
System.out.println(msg);
}
public void playerChecker() {
  EventManager.getSingleton().addEvent(
    new Event() {
        public void execute(EventContainer c) {
	    online = new JLabel(""+PlayerHandler.getPlayerCount());
            sM("Checking players...");
        }
    }, 2500); // executes after 2,000 ms = 2 seconds
};

}